package model.registro;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class RegistroIndicePesoGlobal extends Registro {
	private int nroAparicion;
	private float pesoGlobal;
	
	
	public RegistroIndicePesoGlobal(int nAparicion,  float peso){
		this.nroAparicion=nAparicion;
		this.pesoGlobal=peso;
	}
	
	public RegistroIndicePesoGlobal() {
		// TODO Auto-generated constructor stub
	}

	public int getNroAparicion() {
		return nroAparicion;
	}
	
	public void setNroAparicion(int nroAparicion) {
		this.nroAparicion = nroAparicion;
	}
	
	public float getPesoGlobal() {
		return pesoGlobal;
	}
	
	public void setPesoGlobal(float pesoGlobal) {
		this.pesoGlobal = pesoGlobal;
	}


	public byte[] convertirRegistroABytes() throws IOException {
		
		ByteArrayOutputStream bytesRegistro = new ByteArrayOutputStream();
		DataOutputStream output = new DataOutputStream(bytesRegistro);

		output.writeInt(nroAparicion);
		output.writeFloat(getPesoGlobal());
		return bytesRegistro.toByteArray();
	}
	
	public void convertirBytesARegistro(byte[] xBytesAConvertir) throws IOException {

		ByteArrayInputStream bytesRegistro = new ByteArrayInputStream(xBytesAConvertir);
		DataInputStream input = new DataInputStream(bytesRegistro);

		this.nroAparicion = input.readInt();
		setPesoGlobal(input.readFloat());		
	}

	
	public int getTamanioRegistro() {
		return ConversionesTiposDatos.sizeOfInt() + Float.SIZE/8;
	}
}
